﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace SimpleSM
{
    class SessionT : DB
    {
        public DataTable GetA(int sessionid)
        {
            return this.Select("SELECT s2t.id, t.name, t.application, t.args, s2t.port, s2t.user, s2t.pass, s2t.arg1, s2t.arg2 FROM sessions2type s2t LEFT JOIN type t ON s2t.type_id = t.id WHERE s2t.session_id = @id;", new string[1, 2] { { "@id",  sessionid.ToString() } });
        }

        public DataTable Get(int id)
        {
            return this.Select("SELECT * FROM sessions2type WHERE id = @id;", new string[1, 2] { { "@id", id.ToString() } });
        }

        public bool Copy(int session_id, int newsessionid)
        {
            return this.NonSelect("INSERT INTO sessions2type (session_id, type_id, port, user, pass, arg1, arg2) SELECT @newsessionid, type_id, port, user, pass, arg1, arg2 from sessions2type WHERE session_id = @session_id;", new string[2, 2] { { "@session_id", session_id.ToString() }, { "@newsessionid", newsessionid.ToString() } });
        }

        public bool Add(int session_id, int type_id, int port, string user, string pass, string arg1, string arg2)
        {
            return this.NonSelect("INSERT INTO sessions2type (session_id, type_id, port, user, pass, arg1, arg2) VALUES (@session_id, @type_id, @port, @user, @pass, @arg1, @arg2);", new string[7, 2] { { "@session_id", session_id.ToString() }, { "@type_id", type_id.ToString() }, { "@port", port.ToString() }, { "@user", user}, { "@pass", pass }, { "@arg1", arg1 }, { "@arg2", arg2 } });
        }

        public bool Update(int id, int port, string user, string pass, string arg1, string arg2)
        {
            return this.NonSelect("UPDATE sessions2type SET port = @port, user = @user, pass = @pass, arg1 = @arg1, arg2 = @arg2 WHERE id = @id;", new string[6, 2] { { "@id", id.ToString() }, { "@port", port.ToString() }, { "@user", user }, { "@pass", pass }, { "@arg1", arg1 }, { "@arg2", arg2 } });
        }

        public bool Delete(int id)
        {
            return this.NonSelect("DELETE FROM sessions2type WHERE id = @id;", new string[1, 2] { { "@id", id.ToString() } });
        }
    }
}
